package br.com.vti.sisp_sicrim.model.entity;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

import br.com.crud4j.core.model.Model;
import br.com.vti.sisp_sicrim.model.entity.enums.Status;

/**
 *
 * @author ednardomatos
 */
@Entity
@Table(name = "t_usuario", catalog = "desenvolvimento", schema = "e_seguranca")
@SequenceGenerator(name = "seq_usuario", sequenceName = "e_seguranca.seq_usuario", initialValue = 1, allocationSize = 1)
public class Usuario implements Model<Integer> {
    
    private static final long serialVersionUID = 8015748301821626393L;
    
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_usuario")
    private Integer id;
    
    @NotEmpty
    @NotNull
    @Basic(optional = false)
    @Size(min = 1, max = 100)
    private String nome;
    
    @NotEmpty
    @NotNull
    @Basic(optional = false)
    @Size(min = 1, max = 100)
    private String orgao;
    
    @NotEmpty
    @NotNull
    @Basic(optional = false)
    @Size(min = 1, max = 20)
    private String matricula;
    
    @Column(columnDefinition="bpchar(1) default 'A'")
    private Status status;
    
    @NotEmpty
    @NotNull
    @Basic(optional = false)
    @Size(min = 1, max = 100)
    private String senha;
    
    @ManyToOne
    @JoinColumn(name = "perfil", referencedColumnName = "id")
    private PerfilUsuario perfil;

    public Usuario() {
    }

    public Usuario(Integer id) {
        this.id = id;
    }

    public Usuario(Integer id, String nome, String orgao, String matricula, String senha) {
        this.id = id;
        this.nome = nome;
        this.orgao = orgao;
        this.matricula = matricula;
        this.senha = senha;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getOrgao() {
        return orgao;
    }

    public void setOrgao(String orgao) {
        this.orgao = orgao;
    }

    public String getMatricula() {
        return matricula;
    }

    public void setMatricula(String matricula) {
        this.matricula = matricula;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

    public PerfilUsuario getPerfil() {
        return perfil;
    }

    public void setPerfil(PerfilUsuario perfil) {
        this.perfil = perfil;
    }

    public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	@Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Usuario)) {
            return false;
        }
        Usuario other = (Usuario) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Usuario[ id=" + id + " ]";
    }
    
}
